package controller;

import model.BlogDao;
import model.UserDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2023-12-24
 * Time：23:17
 */
@WebServlet("/userdelete")
public class AdminDeleteUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf8");
        String userId = req.getParameter("userId");
        int uId = Integer.parseInt(userId);
        UserDao userDao = new UserDao();
        userDao.deleteById(uId);
        BlogDao blogDao = new BlogDao();
        blogDao.deleteByUserId(uId);
        resp.sendRedirect("user_list.html");
    }
}
